﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using UtilZ.Dotnet.Ex.Base;
using UtilZ.Dotnet.Ex.Communication.Net.Base;
using UtilZ.Dotnet.Ex.Model;

namespace UtilZ.Dotnet.Ex.Communication.Net.Ftp
{
    /// <summary>
    /// ftp格式辅助类
    /// </summary>
    internal class DataTransferFormatHelper
    {
        public static DataSource ConvertToBufferData(FtpDataTransferFormats dataTransferFormat, string text)
        {
            byte[] buffer;
            switch (dataTransferFormat)
            {
                case FtpDataTransferFormats.ASCII:
                    buffer = Encoding.UTF8.GetBytes(text);
                    break;
                case FtpDataTransferFormats.Image:
                    buffer = Encoding.ASCII.GetBytes(text);
                    //todo..还需要怎么处理???
                    break;
                case FtpDataTransferFormats.EBCDIC:
                default:
                    ZLog.ZLoger.Warn($"ftp服务端未实现的传输格式类型\"{dataTransferFormat.ToString()}\"");
                    buffer = new byte[0];
                    break;
            }

            return new DataSource(buffer);
        }




        //public static void ConvertToBufferData(FtpDataTransferFormats dataTransferFormat, byte[] buffer, int offset, int count)
        //{
        //    byte[] retBuffer;
        //    switch (dataTransferFormat)
        //    {
        //        case FtpDataTransferFormats.ASCII:
        //            string text = Encoding.ASCII.GetString(buffer, offset, count);
        //            retBuffer = buffer;
        //            break;
        //        case FtpDataTransferFormats.Image:
        //            buffer = Encoding.ASCII.GetBytes(text);
        //            //todo..还需要怎么处理???
        //            break;
        //        case FtpDataTransferFormats.EBCDIC:
        //        default:
        //            ZLog.ZLoger.Warn($"ftp服务端未实现的传输格式类型\"{dataTransferFormat.ToString()}\"");
        //            buffer = new byte[0];
        //            break;
        //    }

        //    return new BufferData(buffer);
        //}
    }
}
